﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Nautilus_Password_Reset {

	public static class Cryptography {

		public static string HashPassword(string salt, string password) {
			// Create a new instance of the hash crypto service provider.
			HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();
			// Convert the data to hash to an array of Bytes.
			byte[] bytValue = Encoding.UTF8.GetBytes(password+salt);
			// Compute the Hash. This returns an array of Bytes.
			byte[] bytHash = hashAlg.ComputeHash(bytValue);
			// Optionally, represent the hash value as a base64-encoded string, 
			// For example, if you need to display the value or transmit it over a network.
			string base64 = Convert.ToBase64String(bytHash);

			return base64;
		}

		public static string CreateRandomString(int size) {
			// Generate a cryptographic random number using the cryptographic 
			// service provider
			var rng = new RNGCryptoServiceProvider();
			var buff = new byte[size];
			rng.GetBytes(buff);

			// Return a Base64 string representation of the random number
			return Convert.ToBase64String(buff);
		}

	}

}